package com.anolesoft.amljmes.foreknow.service.impl;

import com.anolesoft.amljmes.foreknow.bo.MesBzzPtdmx;
import com.anolesoft.amljmes.foreknow.bo.MesBzzQfbldmx;
import com.anolesoft.amljmes.foreknow.mapper.MesBzzPtdmxMapper;
import com.anolesoft.amljmes.foreknow.service.MesBzzPtdmxService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class MesBzzPtdmxServiceImpl implements MesBzzPtdmxService {

    @Autowired
    private MesBzzPtdmxMapper mapper;
// 保留过查询
    @Override
    public List<MesBzzPtdmx> querylist(Map map) {
        List<String> you = (List<String>) map.get("you");
        map.put("list",you);
        List<MesBzzPtdmx> list = mapper.querylist(map);
        return list;
    }
// 未保留查询
    @Override
    public List<MesBzzPtdmx> querylist1(Map map) {
        List<String> wu = (List<String>) map.get("wu");
        map.put("list",wu);
        List<MesBzzPtdmx> list = mapper.querylist1(map);
        for (MesBzzPtdmx mx:
             list) {
            MesBzzQfbldmx qfbldmx = new MesBzzQfbldmx();
            qfbldmx.setBlsl(mx.getQuantityOfMissingParts());
            mx.setQfbldmx(qfbldmx);
        }
        return list;
    }

    @Override
    public Map count(Map map) {
        List<String> ids = (List<String>) map.get("list");
        List<String> youids = new ArrayList<>();
        List<String> wuids = new ArrayList<>();
//        根据id查询是否拥有铅封保留单明细(是否保留过)
        for (String id:
        ids) {
            int a = mapper.count(id);
            if (a != 0) {
                // 保留过
                youids.add(id);
            } else {
                // 没有保留或已经撤回
                wuids.add(id);
            }
        }
        Map map1 = new HashMap();
        map1.put("you",youids);
        map1.put("wu",wuids);
        return map1;
    }
}
